/*顾客链表实现*/
/*新建链表节点*/
customer *new_customer()
{
    customer *p;
    p = (customer *)malloc(sizeof(customer));
    p->next = NULL;
}
/*用桌号寻找顾客*/
customer *find_customer(char *id, customer *head)
{
    while (head->next)
    {
        if (!strcmp(head->next->_table->id, id))
        {
            return head->next;
        }
        head = head->next;
    }
    return NULL;
}
/*用桌号删除顾客*/
customer *del_customer(char *id, customer *head)
{
    customer *t = head;
    while (t->next)
    {
        if (!strcmp(t->next->_table->id, id))
        {
            t->next = t->next->next;
            return head;
        }
        t = t->next;
    }
    return head;
}
/*遍历顾客,输出未付款的*/
void unpaid_customer(customer *head)
{
    printf("未付款的顾客:\n");
    customer *t = head;
    while (t->next)
    {
        t = t->next;
        printf("%s\n", t->_table->id);
    }
}
/*计算总价*/
void cal(customer *c)
{
    int i;
    c->price = 0;
    for (i = 0; i < c->size; i++)
    {
        c->price += c->dish_num[i] * c->list[i].price;
    }
}
float cost(customer *c)
{
    int i;
    float ret = 0;
    for (i = 0; i < c->size; i++)
    {
        ret += c->dish_num[i] * c->list[i].cost;
    }
}
/*小票*/
void bill(customer *c)
{
    printf("\t%s餐桌小票\n\n", c->_table->id);
    printf("菜品\t数量\t单价(元)\n");
    int i = 0;
    printf("------------------------\n");
    while (i < c->size)
    {
        printf("%s\t", c->list[i].name);
        printf("%d\t", c->dish_num[i]);
        printf("%f\n", c->list[i].price);
        i++;
    }
    cal(c);
    printf("------------------------\n");
    printf("总价:\t￥%.1f", c->price);
    FILE *f = fopen("daily-data.log", "a+");
    while (i < c->size)
    {
        fprintf(f, "%s\t", c->list[i].name);
        fprintf(f, "%d\n", c->dish_num[i]);
        i++;
    }
    fclose(f);
    f = fopen("day-book.log", "a+");
    fprintf(f, "%f\t%f\n", c->price, cost(c));
    fclose(f);
}